<?php

require_once 'business/AccountManager.php';
require_once 'const/RequestConst.php';

class AccountController extends Zend_Controller_Action {

    public function init() {
        /* Initialize action controller here */
    }

    public function indexAction() {
        // action body
    }

    public function verityAction() {
        $request = $this->getRequest();
        $response = $this->getResponse();
        $email = $request->getParam(P_EMAIL);
        $password = $request->getParam(P_PASSWORD);
        $result = Business_AccountManager::verify($email, $password);
        if ($result == true) {
            $returnURL = $request->getParam(P_RETURNURL);
            if (strlen($returnURL) == 0) {
                $response->setRedirect("/profile/list");
            } else {
                $response->setRedirect($returnURL);
            }
        }
    }

    public function logoutAction() {
        Business_AccountManager::logout($this->getResponse(), "/");
    }

    public function loginAction() {
        $request = $this->getRequest();
        $returnURL = $request->getParam(P_RETURNURL);
        $redirectURL = VERIFY_URL . "?" . P_RETURNURL . "=" . urlencode($returnURL);
        $this->view->actionURL = $redirectURL;
    }

    public function registerAction() {

    }

    public function doregisterAction() {
        $request = $this->getRequest();
        $email = $request->getParam(P_EMAIL);
        $password = $request->getParam(P_PASSWORD);
        $name = $request->getParam(P_NAME);
        $address = $request->getParam(P_ADDRESS);
        $phone = $request->getParam(P_PHONE);
        //
        $registerInfo = new Application_Model_RegisterInfo($email, $password, $name, $address, $phone);
        $result = Business_AccountManager::register($registerInfo);
        $response = $this->getResponse();
        if ($result) {
            $response->setRedirect("/");
        } else {
            $response->setRedirect("/account/register");
        }
    }

}

